home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / redo / redoUnSetRootEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.3 KB  |  254 lines

  1. /*
  2.  *   $RCSfile: redoUnSetRootEntry.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:58 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "trans.h"
  61. #include "openlog.h"
  62. #include "io_extfuncs.h"
  63. #include "bf_extfuncs.h"
  64. #include "util_funcs.h"
  65. #include "trans_extfuncs.h"
  66. #include "redo_extfuncs.h"
  67. #include "thread_globals.h"
  68. #include "log_globals.h"
  69. #include "log_extfuncs.h"
  70.  
  71.  
  72.  void
  73. redoUnSetRootEntry (
  74.  
  75.     LOGRECORDHDR            *record 
  76. )
  77. {
  78.  
  79.     register ROOTENTRY        *current;
  80.     register ROOTENTRY        *end;
  81.     register VOLREC            *volRec;
  82.     register GROUPLINK        *rootLink;
  83.     register DIRTYPAGEINFO    *dirtyInfo;
  84.     char                    *oldData;
  85.     int                        oldDataSize;
  86.     ROOTPAGE                *rootPage;
  87.     PID                        pid;
  88.     VOLID                    volid;
  89.     ROOTENTRYLOGINFO        *entryInfo;
  90.  
  91.  
  92.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN));
  93.  
  94.     /*
  95.      *    get a pointer to the name in the record
  96.      */
  97.     volid = record->actionPid.volid;
  98.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("volid:%d", volid));
  99.  
  100.     /*
  101.      *    construct the pid
  102.      */
  103.     pid.volid = volid;
  104.     pid.page = ROOTPAGEADDR;
  105.     SM_ASSERT(LEVEL_3, ROOTPAGEADDR == record->actionPid.page);
  106.  
  107.     /*
  108.      *    check to see if the page is in the dirty page list
  109.      */
  110.     if ((dirtyInfo = searchDirtyPageTable(&pid)) == NULL)    {
  111.  
  112.         /*
  113.          *    don't need to redo
  114.          */
  115.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  116.         return;
  117.     }
  118.  
  119.     /*
  120.      *  check to see if the lrc on the page is greater than
  121.      *  the lrc in the log record.
  122.      *  Also check the lsn for the case of pages which never made it
  123.      *  back from the client.
  124.      */
  125.     if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
  126.  
  127.         /*
  128.          *  don't need to redo
  129.          */
  130.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  131.         return;
  132.     }
  133.  
  134.     /* get a pointer to information about the entry */
  135.     entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(record, 0);
  136.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name:%s", entryInfo->name));
  137.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
  138.  
  139.     /* get a pointer to the old data and size in the record */
  140.     oldData = GET_LOG_IMAGE(record, 1);
  141.     oldDataSize = GET_LOG_IMAGE_SIZE(record, 1);
  142.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("new data:%s", oldData));
  143.  
  144.     if ((volRec = io_FindVolRec(volid)) == NULL) {
  145.         SM_ERROR(TYPE_FATAL, Active->errno);
  146.     }
  147.  
  148.     /* read in the root page */
  149.     if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
  150.  
  151.         SM_ERROR(TYPE_FATAL, Active->errno);
  152.     }
  153.  
  154.     /*
  155.      *    get a pointer to the root page
  156.      */
  157.     rootPage = (ROOTPAGE *) rootLink->bufFrame;
  158.  
  159.     /*
  160.      *    check to see if the lrc on the page is greater than
  161.      *    the lrc in the log record
  162.      */
  163.     if (compareLRC( &(record->actionLRC), &(rootPage->lrc)) <= 0) {
  164.  
  165.         /*
  166.          *    don't need to redo
  167.          *    mark the page lsn
  168.          */
  169.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  170.         dirtyInfo->lrc = rootPage->lrc;
  171.  
  172.         /*
  173.          *    release the page
  174.          */
  175.         signalSemaphore( &(rootLink->pageHash->semaphore) );
  176.         bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
  177.         return;
  178.     }
  179.  
  180.     /*
  181.      *    Initialize the search variables
  182.      */
  183.     current = &(rootPage->entry[0]);
  184.     end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
  185.  
  186.     /* 
  187.      *    This entry already existed, but the set operation
  188.      *    changed the data, so search for the entry and
  189.      *    change the data.
  190.      */
  191.     while (current < end)   {
  192.  
  193.         /*
  194.          *  check to see if the slot is free
  195.          */
  196.         if (current->flags != ROOT_FREE)    {
  197.  
  198.             /*
  199.              *  check to see if the name matches
  200.              */
  201.             if (!strcmp(current->name, (char *)entryInfo->name))   {
  202.  
  203.                 TRPRINT(TR_IO, TR_LEVEL_2, ("found name at slot:%d", current->index));
  204.                 /*
  205.                  *    See if the root entry should be marked as a 
  206.                  *     free entry slot.
  207.                  */
  208.                 if (entryInfo->oldFlags == ROOT_FREE) {
  209.                     
  210.                     /*
  211.                      *    free the entry
  212.                      */
  213.                     current->flags = ROOT_FREE;
  214.                 } else {
  215.  
  216.                     /*
  217.                      *  restore the old information
  218.                      */
  219.                     bcopy(oldData, current->data, oldDataSize);
  220.                     current->dataSize = oldDataSize;
  221.                 }
  222.  
  223.                 /*
  224.                  *    mark the lsn
  225.                  *    Set up the firstLSN/LRC for the page
  226.                  */
  227.                 rootPage->lrc = record->actionLRC;
  228.                 DEPEND_LOG(rootLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  229.                 TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d",
  230.                         rootPage->lrc.count));
  231.  
  232.                 /* 
  233.                  *    signal the semaphore, unfix the page and return
  234.                  */
  235.                 signalSemaphore( &(rootLink->pageHash->semaphore) );
  236.                 bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
  237.                 return;
  238.             }
  239.         }
  240.         
  241.         /*
  242.          *    look at the next entry
  243.          */
  244.         current++;
  245.     }
  246.  
  247.     /*
  248.      *    There should be a matching entry since history is being
  249.      *    redone.  So, return an error.
  250.      */
  251.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name not found"));
  252.     SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
  253. }
  254.